﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFlow : MonoBehaviour {
    public GameObject follow; //跟随的物体
    public float smothing = 5f; //相机跟随的速度
    Vector3 offset; //相机与物体相对偏移位置
    Vector3 vectorY = new Vector3(0, 1.75f, 0);
    Vector3 dieRotation = new Vector3(0,90f,0);
    public bool ifDie;

    void Start () {
        transform.position = follow.transform.position;
        offset = transform.position - follow.transform.position;
    }

    void FixedUpdate () {
        if (!ifDie) {
            Vector3 target = follow.transform.position + offset + vectorY;
            //摄像机自身位置到目标位置平滑过渡
            transform.rotation= follow.transform.rotation;
            transform.position = target;
            //transform.position = Vector3.Lerp (transform.position, target, smothing * Time.deltaTime);
        }
        else {
            transform.localEulerAngles = new Vector3(90f,0,0);
            Vector3 target = follow.transform.position + 10 * vectorY;
            transform.position = Vector3.Lerp (transform.position, target, smothing * Time.deltaTime);
        }
        
    }
}